package com.yan.furns.dao.impl;

import com.yan.furns.dao.BasicDAO;
import com.yan.furns.dao.OrderItemDAO;
import com.yan.furns.entity.OrderItem;

import java.util.List;

/**
 * @author Yzb
 * @version 1.0
 */
public class OrderItemDAOImpl extends BasicDAO<OrderItem> implements OrderItemDAO {

	@Override
	public int saveOrderItem(OrderItem orderItem) {
		String sql = "insert into order_item (`id`, `name`, `price`, `count`, `total_price`, " +
				"`order_id`) values (?,?,?,?,?,?)";

		return update(sql, orderItem.getId(), orderItem.getName(), orderItem.getPrice(), orderItem.getCount(), orderItem.getTotalPrice(), orderItem.getOrderId());
	}

	@Override
	public List<OrderItem> getOrderItemsByOrderId(String orderId) {
		String sql = "select `id`, `name`, `price`, `count`, `total_price` totalPrice from order_item where order_id = ?";
		return queryMulti(sql, OrderItem.class, orderId);
	}
}
